<template>
  <div class="box">
    <div class="login-container">
      <el-form
        status-icon
        ref="ruleFormRef"
        :model="logForm"
        label-width="40px"
        class="loginform"
      >
        <div class="login">
          <h2>登录</h2>
        </div>
        <el-form-item prop="admin_name">
          <el-input
            v-model="logForm.admin_name"
            autocomplete="off"
            placeholder=""
            class="inpu1"
          />
        </el-form-item>
        <el-form-item prop="pwd">
          <el-input
            v-model="logForm.pwd"
            type="password"
            autocomplete="off"
            class="inpu1"
          />
        </el-form-item>
        <el-form-item>
          <el-button class="botto" type="primary" @click="login"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { toRefs, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
// 接口
import { loginList } from "../../api/login/index";
// 路由跳转
import router from "../../router/router";

const data = reactive({
  //接口数据
  logForm: {
    admin_name: "admin",
    pwd: "",
  },
});
const { logForm } = toRefs(data);
// 登录

const login = async () => {
  const res: any = await loginList(data.logForm);
  console.log("res---", res);
  if (res.code === "00000") {
    localStorage.setItem("token", res.token);
    localStorage.setItem("userInfo", JSON.stringify(res.admin));

    ElMessage({
      message: "登录成功",
      type: "success",
    });
    router.push("./listView"); //跳转页面
  } else {
    ElMessage({
      message: res.msg,
      type: "error",
    });
  }
};
</script>

<style scoped lang="less">
.box {
  height: 100%;
}
.login-container {
  min-height: 100%;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background-image: url("https://s1.z6r7.com/i/2022/11/09/ngwtja.jpg");
  background-size: cover;
  background-position: 50%;
}
.loginform {
  position: relative;
  /* width: 350px; */
  width: 520px;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  margin-top: 180px;
  /* background-color: aqua; */
}
.title {
  position: relative;
  margin: 0 auto;
}
.login {
  margin-bottom: 30px;
  color: #fff;
  text-align: center;
}
.el-form-item__content {
  margin: 0;
}
.inpu1 {
  border-radius: 10px !important;
  width: 448px;
  height: 50px;
  background: transparent;
}
/deep/.el-input__wrapper {
  border-radius: 10px !important;

  background-color: rgb(40, 52, 67) !important;
  padding-left: 50px;
  border: 0 !important;
}
/deep/.el-input__inner {
  border: 0 !important;
  color: #fff !important;
}
.botto {
  width: 450px;
  height: 36px;
  line-height: 50px;
  background-color: #1890ff;
  border: #1890ff;
}
</style>